﻿using Qins.PluginInterface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Qins.Plugins.NotifyIcon
{
    /// <summary>
    /// SetUrlWin.xaml 的交互逻辑
    /// </summary>
    public partial class SetUrlWin : Window
    {
        public SetUrlWin()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string urlstr = tburl.Text;
            if (urlstr.ToLower().IndexOf("http") < 0)
            {
                urlstr = "https://" + urlstr;
            }
            foreach (var pwin in Application.Current.Windows.OfType<Window>())
            {
                if (pwin.Name == "QinNotifyIcon")
                {
                    QinNotifyIcon qni = (QinNotifyIcon)pwin;
                    MessageContent mc = new MessageContent();
                    mc.messageType = MessageConentTypeEnum.OpenUrl;
                    mc.content = urlstr;
                    qni.CallPluginRun("Qins.Plugins.NotifyIcon.QinNotifyIcon", mc);
                    break;
                }
            }

            //MainInfo.MainUrl = urlstr;
            ////Application.Current.MainWindow.Close();
            ////Application.Current.MainWindow = new MainWindow();
            ////Application.Current.MainWindow.Show();
            //MainWindow main = (MainWindow)Application.Current.MainWindow;
            //main.OpenUrl(MainInfo.MainUrl);
            this.Close();
        }
    }
}
